import sys

try:
    # Python 2
    from SimpleHTTPServer import SimpleHTTPRequestHandler
    from BaseHTTPServer import HTTPServer
    from SocketServer import TCPServer
    """
    import os
    print [i for i in os.listdir("D:\\Python27\\Lib") if i.endswith('Server.py')]

    BaseHTTPServer.py
    CGIHTTPServer.py
    DocXMLRPCServer.py
    SimpleHTTPServer.py
    SimpleXMLRPCServer.py
    SocketServer.py
    """
except:
    # Python 3
    from http.server import SimpleHTTPRequestHandler, HTTPServer
    from socketserver import TCPServer

"""
python -m SimpleHTTPServer 8000
"""

Handler  = SimpleHTTPRequestHandler
Server   = TCPServer # HTTPServer or TCPServer
Protocol = "HTTP/1.0"

host = len(sys.argv) < 2 and "127.0.0.1" or sys.argv[1]
port = len(sys.argv) < 3 and 8000 or int(sys.argv[2])  # locale.atoi(sys.argv[2])
server_address = (host, port)

Handler.protocol_version = Protocol
httpd = Server(server_address, Handler)

print "Serving HTTP on http://%s:%d..." % httpd.socket.getsockname()
httpd.serve_forever()

# http://phyeas.iteye.com/blog/354606
# http://blog.csdn.net/ghostfromheaven/article/details/8653421
# http://www.cnblogs.com/itech/archive/2011/12/31/2308697.html
